package com.cxq.unsafe;

/**
 * Created by cxq on 2020/7/25.
 */
public class Tickets  implements Runnable{
    private int ticket = 100;

    @Override
    public void run() {
        while(true){
            if(ticket>0){
                try {
                    //模拟出票时间
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //打印进程号和票号，票数减1
                String name = Thread.currentThread().getName();
                System.out.println("线程"+name+"售票"+ticket--);
            }
        }
    }
}
